<!DOCTYPE html>
<html>
<head>
    <title>欢迎注册</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="keywords"
          content="Shadow Login Form template Responsive, Login form web template,Flat Pricing tables,Flat Drop downs  Sign up Web Templates, Flat Web Templates, Login sign up Responsive web template, SmartPhone Compatible web template, free webdesigns for Nokia, Samsung, LG, SonyEricsson, Motorola web design"/>
    <script type="application/x-javascript"> addEventListener("load", function () {
        setTimeout(hideURLbar, 0);
    }, false);
    function hideURLbar() {
        window.scrollTo(0, 1);
    } </script>
    <link href="/login/css/style.css" rel="stylesheet" type="text/css" media="all"/>
    <link href="//fonts.googleapis.com/css?family=Cormorant+Garamond:300,300i,400,400i,500,500i,600,600i,700,700i"
          rel="stylesheet">
    <link href="//fonts.googleapis.com/css?family=Arsenal:400,400i,700,700i" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="/layui/css/layui.css">
</head>
<body>
<div class="main-agileinfo slider ">
    <div class="items-group">
        <div class="item agileits-w3layouts">
            <div class="block text main-agileits" style="margin: 4em auto; ">
                <span class="circleLight"></span>
                <!-- 表单 -->
                <div class="login-form loginw3-agile">
                    <div class="agile-row">
                        <h1>欢迎注册</h1>
                        <div class="login-agileits-top">
                            <form action="#" method="post">
                                <p>姓名</p>
                                <input type="text" class="name" id="userName" />
                                <p>账号</p>
                                <input type="text" class="name" id="userNumber" />
                                <p>密码</p>
                                <input type="password" class="password" id="userPassword" />
                                <p>确认密码</p>
                                <input type="password" class="password" id="surePassword" />
                                <input type="button" value="注册" style="margin-top: 25px; " onclick="submitRegister()" >
                            </form>
                        </div>
                        <div class="login-agileits-bottom wthree">
                            <h6><a href="/login/loginPage">已有账号？前去登录</a></h6>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="/jquery/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="/layui/layui.js"></script>
<script>
    layui.use(['element','layer'], function(){
        let element = layui.element;
        let layer = layui.layer;

        //注册表单提交
        submitRegister = function(){
            let userName = $('#userName').val();
            let userNumber = $('#userNumber').val();
            let userPassword = $('#userPassword').val();
            let surePassword = $('#surePassword').val();
            if(userName == null || userName === ''){
                layer.msg("请输入姓名！")
            }else if(userNumber == null || userNumber === ''){
                layer.msg("请输入账号！")
            }else if(userPassword == null || userPassword === ''){
                layer.msg("请输入密码！")
            }else if(surePassword == null || surePassword === ''){
                layer.msg("请输入确认密码！")
            }else if(userPassword !== surePassword){
                layer.msg("两次输入密码不一致,请检查！")
            }else{
                let re = /^[0-9]*$/;
                if(!re.test(userNumber)){
                    layer.msg("账号处请输入数字")
                }else{
                    let obj = {};
                    obj["userName"] = userName;
                    obj["userNumber"] = userNumber;
                    obj["userPassword"] = userPassword;
                    obj["userType"] = 0;
                    $.ajax({
                        type: "POST"
                        ,url : '/login/judgeRegister'
                        ,data: JSON.stringify(obj)
                        ,contentType: "application/json"
                        ,success : function(data) {
                            if (data === 'success') {
                                layer.msg('注册成功');
                                setTimeout(function(){
                                    window.location = "/login/loginPage"
                                },2*1000)
                            }else if(data === 'numberRepeat'){
                                layer.msg('该账号已被注册')
                            } else if(data === 'fail'){
                                layer.msg('发生错误，注册失败')
                            }
                        }
                    });
                }
            }
        }

    });
</script>
</body>
</html>